﻿namespace Resharper.Abstractions.Settings
{
  using System.Xml;
  using JetBrains.Application.Configuration;

  /// <summary>Defines the <see cref="SettingsBase"/> class.</summary>
  public abstract class SettingsBase : IXmlExternalizable
  {
    #region Constants and Fields

    /// <summary>
    /// Gets or sets the shell settings component.
    /// </summary>
    /// <value>The shell settings component.</value>
    protected ShellSettingsComponent ShellSettingsComponent { get; set; }

    #endregion

    #region Implemented Interfaces

    #region IXmlExternalizable

    /// <summary>This method must not fail with null or unexpected Xml!!!</summary>
    /// <param name="element"></param>
    void IXmlExternalizable.ReadFromXml(XmlElement element)
    {
      if (element == null)
      {
        this.Initialize();
        return;
      }

      XmlExternalizationUtil.ReadFromXml(element, this);
    }

    /// <summary>Writes to XML.</summary>
    /// <param name="element">The element.</param>
    void IXmlExternalizable.WriteToXml(XmlElement element)
    {
      XmlExternalizationUtil.WriteToXml(element, this);
    }

    #endregion

    #endregion

    #region Methods

    /// <summary>Initializes this instance.</summary>
    protected virtual void Initialize()
    {
    }

    #endregion
  }
}